<template>
  <div class="card_wrap">
    <el-scrollbar>
      <ul class="icon-list-wrap">
        <li class="icon-item" v-for="(item,index) in list" :key="index"
            @click="copyIcon(item)"
        >
          <svg-icon class="icon-target" :icon="item"/>
          <span class="icon-name">{{ item }}</span>
        </li>
      </ul>
    </el-scrollbar>
  </div>
</template>

<script setup>
import {copy} from "@/utils";
import {computed} from "vue";
import {useStore} from "vuex";
import {toast} from "@/hook/toast";

const store = useStore()
const list = computed(() => {
  return store.getters.iconList
})
function copyIcon(name) {
  copy(`<svg-icon icon="${name}" />`).then(()=>{
    toast({title:'复制成功',type:'success'})
  }).catch(()=>{
    toast({title:'复制失败',type:'error'})
  })
}
</script>

<style lang="scss" scoped>
.icon-list-wrap {
  padding: 0;
  list-style: none;
  margin: 0;
  box-sizing: border-box;
  border-top: 1px solid var(--el-border-color);
  border-left: 1px solid var(--el-border-color);
  border-radius: 4px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);

  .icon-item {
    text-align: center;
    height: 90px;
    font-size: 13px;
    border-right: 1px solid var(--el-border-color);
    border-bottom: 1px solid var(--el-border-color);
    transition: background-color var(--el-transition-duration);
    color: #606266;
    display: flex;
    flex-flow: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    &:hover{
      background-color: var(--el-border-color-extra-light);
      color: var(--brand-color-light);
    }

    .icon-name {
      margin-top: 8px;
      font-size: 16px;
    }

    .icon-target {
      font-size: 30px;
    }
  }
}
</style>